package com.heima.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.heima.bean.Orders;
import com.heima.common.PageParam;
import com.heima.common.R;
import com.heima.dto.OrdersDto;
import com.heima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/order")
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 提交订单
     * @param order
     * @return
     */
    @PostMapping("/submit")
    public R submitOrder(@RequestBody Orders order){
        int row = orderService.add(order);
        if (row > 0) {
            return R.success("提交订单成功！");
        }
        return R.error("提交订单失败！");
    }

    @GetMapping("/userPage")
    public R getUserPage(PageParam pageParam) {
        IPage<Orders> userPage = orderService.getUserPage(pageParam);
        return R.success(userPage);
    }

    @GetMapping("/page")
    public R getPage(PageParam pageParam) {
        IPage<OrdersDto> userPage = orderService.getPage(pageParam);
        return R.success(userPage);
    }

    @PutMapping
    public R updateStatus(@RequestBody Orders orders) {
        int row = orderService.updateStatus(orders);
        if (row > 0) return R.success("success");
        return R.error("fail");
    }



}
